<template>
	<view class="">
		<div @click="changeImage">
			<image :src="'http://localhost:8090'+user.icon" 
			style="width: 50px;
			height: 50px;
			background-color: blanchedalmond;
			border-radius: 100rpx;
			margin-left: 50rpx;"></image>
		</div>
		<navigator url="login/login" v-show="vlog">
			<button type="default" style="margin-left: 50rpx; margin-right: 50rpx;">登录</button>
		</navigator>
		<uni-list v-show="!vlog">
			<uni-list-item title="修改密码"></uni-list-item>
			<uni-list-item title="密码" :rightText="user.telephone"></uni-list-item>
		</uni-list>
		<button type="default" style="margin-left: 50rpx; margin-right: 50rpx;" v-show="!vlog" @click="loginout">退出登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				vlog:true,
				user:{}
			}
		},
		methods: {
			loginout(){
				uni.clearStorage(),
				this.user={},
				this.vlog=true
			},
			changeImage() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						if (res.tempFilePaths.length > 0) {
							let temFilePaths = res.tempFilePaths[0]
							let temFiles = res.tempFiles
							uni.uploadFile({
								url: 'http://localhost:8090/foodapp/uploadheadicon',
								filePath: temFilePaths,
								name: 'file',
								formData: {
									"id": this.user.id,
									'file': temFiles
								},
								success: (uploadFileRes) => {
									let upres = JSON.parse(uploadFileRes.data)
									this.user.icon = upres.headiconpath;
								}
							});
						}
					}
				})
			}
		},
		onShow() {
		this.user =	uni.getStorageSync("user")
		if(this.user!=null&&this.user!=""){
			this.vlog=false
		}
		console.log(this.user);
		}
	}
</script>

<style>

</style>
